// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ESSBO.java

package com.vandagroup.common.bo;

import com.vandagroup.common.db.ESSDataStoreManager;
import com.vandagroup.common.exp.*;
import com.vandagroup.common.po.ESSPL;
import com.vandagroup.common.po.ESSPLQueryInterface;
import com.vandagroup.common.util.Result;
import java.sql.*;

// Referenced classes of package com.vandagroup.common.bo:
//            ESSObject, User, ESSCmd, ESSBean

public class ESSBO extends ESSObject
{

    private User user;

    public ESSBO()
    {
        user = null;
    }

    public void setUser(User user)
    {
        this.user = user;
    }

    public User getUser()
    {
        return user;
    }

    public String getOperName()
    {
        if(user != null)
            return user.getOperName();
        else
            return null;
    }

    public Result retrieve(String sql, ESSPLQueryInterface po)
        throws SQLException, ESSConnectionGetTimeOutException
    {
        return retrieve(sql, po, 0, 0);
    }

    public Result retrieve(String sql, ESSPLQueryInterface po, int page)
        throws SQLException, ESSConnectionGetTimeOutException
    {
        return retrieve(sql, po, 20, page);
    }

    public Result retrieve(String sql, ESSPLQueryInterface po, int pageSize, int page)
        throws SQLException, ESSConnectionGetTimeOutException
    {
        ESSPL pl = new ESSPL();
        return pl.retrieve(sql, po, pageSize, page);
    }

    public Result retrieve(ESSPLQueryInterface po, String whereClause, String orderBy, int page)
        throws SQLException
    {
        return retrieve(po, whereClause, true, orderBy, page);
    }

    public Result retrieve(ESSPLQueryInterface po, String whereClause, boolean appendWhere, String orderBy, int page)
        throws SQLException
    {
        Result result = new Result();
        ESSPL pl = new ESSPL();
        pl.setPO(po);
        pl.setWhereClause(appendWhere, whereClause);
        pl.setOrderBy(orderBy);
        pl.setResultPage(result.getResultSize(), page);
        pl.retrieve();
        result = pl.getResult();
        return result;
    }

    public int executeUpdate(String sql)
        throws SQLException, ESSConnectionGetTimeOutException
    {
        int row;
        row = 0;
        Statement statement = null;
        Connection conn = null;
        try
        {
            conn = ESSObject.getDataStore().getConnection();
            statement = conn.createStatement();
            row = statement.executeUpdate(sql);
        }
        catch(SQLException ex)
        {
            throw ex;
        }
        finally
        {
            ESSObject.getDataStore().freeConnection(conn);
            if(statement != null)
                statement.close();
            conn = null;
            sql = null;
        }
        return row;
    }

    protected final ESSCmd createCommand(String commandName)
    {
        return null;
    }

    protected final ESSBean executeCommand(String commandName, ESSBean dataBean)
        throws ESSCommandNotExistedException, ESSCommandExecuteException, ESSAccessDeniedException
    {
        return null;
    }

    public String getOrgName()
    {
        if(user != null)
            return user.getOrgName();
        else
            return null;
    }
}
